<?php
include_once '../Login/databaseconnection.php';
 $Congeniality=$_POST['Congeniality'];
 $New_Congeniality=$_POST['New_Congeniality'];
 $Function=$_POST['Function'];
 $New_Function=$_POST['New_Function'];
 $Ethinicity=$_POST['Ethinicity'];
 $New_Ethinicity=$_POST['New_Ethinicity'];
$Cen_No=$_SESSION['Census_Number'];
$_SESSION['Cen_No']=$Cen_No;
 $School_Id=$_POST['School_Id'];
 $Principal_Name=$_POST['Principal_Name'];
   $Zone=$_POST['Zone'];
 $Division=$_POST['Division'];
   $Province=$_POST['Province'];
  $District=$_POST['District'];
 $Census_Number=$_POST['Census_Number'];
$Name=$_POST['Name'];
 $Status=$_POST['Status'];
$Type=$_POST['Type'];
  $Grade_Range=$_POST['Grade_Range'];
   $Medium=$_POST['Medium'];
 $Female_Students=$_POST['Female_Students'];
  $Male_Students=$_POST['Male_Students'];
 $Tp_Number=$_POST['Tp_Number'];
  $Fax_Number=$_POST['Fax_Number'];
  $E_Mail=$_POST['E_Mail'];
  $Web_Address=$_POST['Web_Address'];
    $Address=$_POST['Address'];
 $Account_Number=$_POST['Account_Number'];
 date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
	$pervious=mysql_query("SELECT * FROM school WHERE Census_Number='$Cen_No'");
	if($pervious)
	{
	if($per_row=mysql_fetch_array($pervious))
	{
	$Tp_Numberp=$per_row['Tp_Number'];
  $Fax_Numberp=$per_row['Fax_Number'];
  $E_Mailp=$per_row['E_Mail'];
  $Web_Addressp=$per_row['Web_Address'];
 $Account_Numberp=$per_row['Account_Number'];
 $Special_Projectsp=$per_row['Special_Projects'];
	}
	}
  $Special_Projects=$_POST['Special_Projects'];
  $S_Proje="";
  $Special_Projects_other=$_POST['Special_Projects_other'];
$S_Pro="";
for($i=0;$i<sizeof($Special_Projects);$i++)
  {
  if($i==0)
  {
  if($Special_Projects[$i]=="Others(P1.specify)")
  {$S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro="other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro="other_".$spe_other;
  }
  }
  else
  {
  $S_Pro=$Special_Projects[0];
  }
  }
  else
  {
  if($Special_Projects[$i]=="Others(P1.specify)")
  {$S_Proje="yes";
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
    if($spe_other=="")
  {
  $S_Pro=$S_Pro.",other_";
  $_SESSION['errorspo']="Please type the other special projects!";
  }
  else
  {
  $S_Pro=$S_Pro.",other_".$spe_other;
  }
  }
  else
  {
	$S_Pro=$S_Pro.",".$Special_Projects[$i];
	}
	}
	}
    if(($New_Congeniality==""&&$Congeniality=="Select One")||($New_Function==""&&$Function=="Select One")||($New_Ethinicity==""&&$Ethinicity=="Select One")||$Principal_Name==""||$Census_Number==""||$School_Id==""||$Zone==""||$Division==""||$Province==""||$District==""||$Name==""||$Status==""||$Type==""||$Grade_Range==""||$Medium==""||$Female_Students==""||$Male_Students==""||$Address=="")
  {
	  $_SESSION['errorin']="Please check your inputs some of them are null!";
  }
 if(($New_Congeniality!=""||$Congeniality!="Select One")&&($New_Function!=""||$Function!="Select One")&&($New_Ethinicity!=""||$Ethinicity!="Select One")&&$Principal_Name!=""&&$Census_Number!=""&&$School_Id!=""&&$Zone!=""&&$Division!=""&&$Province!=""&&$District!=""&&$Name!=""&&$Status!=""&&$Type!=""&&$Grade_Range!=""&&$Medium!=""&&$Female_Students!=""&&$Male_Students!=""&&$Address!="")
  {
  	if($New_Ethinicity!="")
	{
	$Ethinicity=$New_Ethinicity;
	}
	if($New_Congeniality!="")
	{
	$Congeniality=$New_Congeniality;
	}
	if($New_Function!="")
	{
	$Function=$New_Function;
	}
   if(($Tp_Numberp!=""&&$Tp_Number=="")||($Fax_Numberp!=""&&$Fax_Number=="")||($E_Mailp!=""&&$E_Mail=="")||($Web_Addressp!=""&&$Web_Address=="")||($Account_Numberp!=""&&$Account_Number=="")||($Special_Projectsp!=""&&$Special_Projects==""))
  {
   $_SESSION['errorempt']="You have deleted some values If you want to put them,Please update again!";
  }
    if($S_Proje=="yes")
  {
  $s_other=$_POST['Special_Projects_Others'];
   $spe_other=mysql_real_escape_string($s_other);
	  if($spe_other!="")
  {
  $sql=mysql_query("UPDATE school SET Congeniality='$Congeniality',Function='$Function',Ethinicity='$Ethinicity',Principal_Name='$Principal_Name',Census_Number='$Census_Number',School_Id='$School_Id',Zone='$Zone',Division='$Division',Province='$Province',District='$District',Name='$Name',Status='$Status',Type='$Type',Grade_Range='$Grade_Range',Medium='$Medium',Female_Students='$Female_Students',Male_Students='$Male_Students',Tp_Number='$Tp_Number',Fax_Number='$Fax_Number',E_Mail='$E_Mail',Web_Address='$Web_Address',Special_Projects='$S_Pro',Address='$Address',Account_Number='$Account_Number',Last_Updated_Date='$t_d' WHERE Census_Number='$Cen_No'");
unset($_SESSION['Census_Number']);
if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="This record is successfully updated!";
}

  if(mysql_affected_rows()==0)
  {
 $_SESSION['error']="Sorry unable to update this record!";
  }
  }
  else
  {
   $_SESSION['error']="Please specify other project of this school!";
  }
  }
  else
  {
   $sql=mysql_query("UPDATE school SET Congeniality='$Congeniality',Function='$Function',Ethinicity='$Ethinicity',Principal_Name='$Principal_Name',Census_Number='$Census_Number',School_Id='$School_Id',Zone='$Zone',Division='$Division',Province='$Province',District='$District',Name='$Name',Status='$Status',Type='$Type',Grade_Range='$Grade_Range',Medium='$Medium',Female_Students='$Female_Students',Male_Students='$Male_Students',Tp_Number='$Tp_Number',Fax_Number='$Fax_Number',E_Mail='$E_Mail',Web_Address='$Web_Address',Special_Projects='$S_Pro',Address='$Address',Account_Number='$Account_Number' WHERE Census_Number='$Cen_No'");
unset($_SESSION['Census_Number']);
if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="This record is successfully updated!";
}

  if(mysql_affected_rows()==0)
  {
 $_SESSION['error']="Sorry unable to update this record!";
  }  
}
}
?>

